package com.nwpu.coursesupport.controller;

import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.nwpu.coursesupport.entity.bean.JSONResult;

@Controller
@RequestMapping("/accontrol")
public class AssistantCourseController extends AbstractController {

    @RequestMapping(value="/ajaxCreate",method=RequestMethod.POST)
    @ResponseBody
    public JSONResult ajaxCreate(@RequestParam("data") String data) {
    	JSONResult result = invokeService("assistantCourse", "create", data);
        return result;
    }
    
    @RequestMapping("/ajaxListCourse")
    @ResponseBody
    public JSONResult ajaxListCourse(){
    	Integer	id=(Integer) getSession().getAttribute("id");
    	JSONResult result = invokeService("assistantCourse", "getCourseByAid", "{\"id\":\"" + id + "\"}");
        return result;
    }
    
    @RequestMapping("/ajaxListAssistant")
    @ResponseBody
    public JSONResult ajaxListAssistant(@RequestParam("id") Integer id){
    	JSONResult result = invokeService("assistantCourse", "getAssistantByCid", "{\"id\":\"" + id + "\"}");
        return result;
    }
    
    @RequestMapping("/listAssistant")
    public String listAssistant(@RequestParam("id") Integer id ,HttpServletRequest request){
    	JSONResult result = invokeService("assistantCourse", "getAssistantByCid", "{\"id\":\"" + id + "\"}");
    	request.setAttribute("data",this.parseData(result));
    	return "/teapage/courseAssistant";
    }
    
    
    @RequestMapping("/ajaxListCourseView")
    public String ajaxListCourseView(HttpServletRequest request){
    	Integer	id=(Integer) getSession().getAttribute("id");
    	JSONResult result =invokeService("assistantCourse", "getCourseViewByAid", "{\"id\":\"" + id + "\"}");
    	request.setAttribute("data", this.parseData(result));
    	return "/teapage/teacherIndex";
    }

    @RequestMapping(value="/ajaxDelete",method=RequestMethod.POST)
    @ResponseBody
    public JSONResult ajaxDelete(@RequestParam("id") Integer id) {
    	JSONResult result = invokeService("assistantCourse", "remove", "{\"id\":\"" + id + "\"}");
        return result;
    }
    
    @RequestMapping(value="/batchDelete",method=RequestMethod.POST)
    @ResponseBody
    public JSONResult batchAjaxDelete(@RequestParam("data")String data){
    	 JSONResult result = invokeService("assistantCourse", "removeAll", data);
         return result;
    }
    
    @RequestMapping("/ajaxListData")
    @ResponseBody
    public JSONResult ajaxListData(@RequestParam("data") String data) {
    	 JSONResult result = invokeService("assistantCourse", "listData", data);
         return result;
    }


}